<!--
 * @Author: your name
 * @Date: 2020-08-22 01:51:42
 * @LastEditTime: 2020-08-27 20:29:38
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \exam-list\src\components\checkpaper\PaperDetail.vue
-->
<template>
  <div>
    <Card>
      <Form ref="loginFromRef" :model="formValidate">
        <FormItem label="请输入考试题目">
          <Input size="large" type="text" placeholder="请输入考试题目" v-model="formValidate.username" />
        </FormItem>
        <Select v-model="modelTwo" style="width:200px" label="请选择考试类型">
          <Option
            v-for="item in examType"
            :value="item.exam_id"
            :key="item.exam_id"
            placeholdren="请选择考试类型"
          >{{ item.exam_name }}</Option>
        </Select>
        <Select v-model="modelOne" style="width:200px" label="考试课程">
          <Option
            v-for="item in examlist"
            :value="item.subject_id"
            :key="item.subject_id"
            placeholdren="请选择课程"
          >{{ item.subject_text }}</Option>
        </Select>
        <FormItem label="设置题数">
          <Input size="large" type="text" placeholder="请设置题数" v-model="formValidate.num" />
        </FormItem>
        <FormItem label="设置开始时间">
          <Input size="large" type="text" placeholder="设置开始时间" v-model="formValidate.first" />
        </FormItem>
        <FormItem label="设置结束时间">
          <Input size="large" type="text" placeholder="设置结束时间" v-model="formValidate.last" />
        </FormItem>
      </Form>
      <Button type="primary" @click="establish">Primary</Button>
    </Card>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex'
export default {
  data() {
    return {
      modelOne: '',
      modelTwo: '',
      formValidate: {
        username: '',
        num: '',
        first: '',
        last: ''
      }
    }
  },
  computed: {
    ...mapState('Exam', ['examlist', 'examType'])
  },
  methods: {
    ...mapActions('Exam', ['getList', 'ExamType', 'postExamList']),
    handleSubmit(name) {
      this.$refs[name].validate(valid => {
        if (valid) {
          this.$Message.success('提交成功!')
        } else {
          this.$Message.error('表单验证失败!')
        }
      })
    },
    handleReset(name) {
      this.$refs[name].resetFields()
    },
    establish() {
      const obj = {
        title: this.formValidate.username,
        number: this.formValidate.num * 1,
        exam_id: this.modelTwo,
        subject_id: this.modelOne,
        start_time: this.formValidate.first * 1,
        end_time: this.formValidate.last * 1
      }
      this.postExamList(obj)
      this.formValidate = {}
      this.$router.push({ path: 'exam/edit' })
    }
  },
  created() {
    this.getList()
    this.ExamType()
    console.log(this.examlist)
  }
}
</script>

<style lang="scss" scoped>
</style>
